package demo.database.hsqldb;

import java.sql.Connection;

import com.titan.core.utils.db.DBUtils;
import com.titan.core.utils.db.RecordSet;


/**
 *
 *
 * @author Administrator
 *
 */
public class MemoryOnlyTest {
    public static void main(String[] args) {
        Connection conn = null;
        RecordSet record = null;
        try {
            conn = MemoryOnlyDBManager.getConnection();
            
            DBUtils.execute(conn, "CREATE TABLE t(c1 VARCHAR(30), c2 DECIMAL, ts TIMESTAMP, id IDENTITY, dt DATE, ti TIME)");
            for (int i = 0; i < 5; i++) {
                DBUtils.execute(conn, "insert into t(c1,c2,ts,id,dt,ti) values('"+i+"', "+i+", TIMESTAMP'2000-12-10 10:11:12', null, DATE'2000-12-10', TIME'10:11:12')");
            }
            
            record = DBUtils.executeQueryToRecordSet(conn, "SELECT * FROM t");
            while(record.moveNext()) {
              System.out.println(record.toMap());
            }            
            
            DBUtils.execute(conn, "SET SCHEMA INFORMATION_SCHEMA");
            record = DBUtils.executeQueryToRecordSet(conn, "SELECT table_name FROM SYSTEM_TABLES where table_type = 'TABLE' order by table_name");
            while(record.moveNext()) {
              System.out.println(record.toMap());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DBUtils.close(record);
            DBUtils.close(conn);
        }
    }
}

